//
//  Rank_PeopleInfoBottomView.m
//  YLProject
//
//  Created by 张伯林 on 2018/1/28.
//  Copyright © 2018年 WY. All rights reserved.
//

#import "Rank_PeopleInfoBottomView.h"
#import "Rank_PeopleInfo_Botton.h"
@implementation Rank_PeopleInfoBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, Screen_Width, 50)];
    if (self) {
        
        [self createView];
    }
    return self;
}
-(void)createView{
    self.backgroundColor = YLRandom(247, 107, 109, 1);
    NSArray *titleArray = @[@"关注",@"私聊",@"视频聊"];
    for(NSInteger index = 0; index < 3; index ++){
        Rank_PeopleInfo_Botton *button = [[Rank_PeopleInfo_Botton alloc] initWithFrame:CGRectMake(Screen_Width / 3 * index , 0, Screen_Width / 3, self.height)];
        [button setText:titleArray[index] imageName:@""];
        button.block = ^{
            if (self.touchBlock) {
                self.touchBlock(index);
            }
            if (index == 0) {
                [self changeViewAtt];
            }
        };
        [self.buttonArray addObject:button];
        [self addSubview:button];
    }
}
- (IBAction)followButtonClick:(UIButton *)sender {
    if (self.touchBlock) {
        self.touchBlock(Rank_PeopleInfoBottomFollow);
    }
    [self changeViewAtt];
}
- (IBAction)privateChatClick:(UIButton *)sender {
    if (self.touchBlock) {
        self.touchBlock(Rank_PeopleInfoBottomPrivateChat);
    }
}
- (IBAction)vudioChatClick:(UIButton *)sender {
    if (self.touchBlock) {
        self.touchBlock(Rank_PeopleInfoBottomVideoChat);
    }
}
-(void)changeViewAtt{
    for (NSInteger index = 0; index < self.buttonArray.count; index ++) {
        Rank_PeopleInfo_Botton *button = self.buttonArray[index];
        if (index == 0) {
            button.hidden = YES;
        }else{
            button.frame = CGRectMake(Screen_Width / 2 * (index - 1), button.frame.origin.y, Screen_Width / 2, button.height);
        }
    }
}
-(NSMutableArray *)buttonArray{
    if (!_buttonArray) {
        _buttonArray = [NSMutableArray array];
    }
    return _buttonArray;
}
@end
